-- 需要将libmysql.dll放在根目录 和 clibs/luasql
package.path="clibs"..";..\?.lua"..";..\?.lua"
print("------------------------------")
luasql = require "luasql.mysql"
json=require("cjson")
client = luasql.mysql();
--创建连接
conn=assert(client:connect("test","root","123456","127.0.0.1",3306)); --数据库名，用户名，密码，IP，端口
print("hello","测试")
if conn == nil then
    print("连接失败");
    os.exit();
end
-- 解决中文乱码情况
conn:execute("SET NAMES gb2312")
--查询
rs=conn:execute("select * from sys_user order by id desc");
list={}
row = rs:fetch({},"a")
i=1
while row do
    item={
    	name=row.user_name,
    	id=row.id,
    	sex=row.sex,
    	age=row.age
    }
    
    list[i]=item
    row = rs:fetch(row,"a");
    i=i+1
end
rs:close()
conn:close()
client:close()
js=json.encode(list)

response={
		code=200,
    body=js,
    header={}
}
response.header["Content-Type"]="application-json;charset=utf-8"




